﻿#include "csqlmanager.h"

#include <QCoreApplication>
#include <QSqlError>
#include <QSqlQuery>
#include <QVariant>

#include "sharedDefine.h"

#ifdef _N_Debug_
#include <QDebug>
#endif

CSQLManager::CSQLManager()
{

}

CSQLManager::~CSQLManager()
{
}

bool CSQLManager::exec(QSqlDatabase db, QString sql)
{
    QSqlQuery sqlQuery(db);
    if(!sqlQuery.exec(sql))
    {
#ifdef _N_Debug_
        qDebug() << "Error[" << sql <<"].  " << sqlQuery.lastError();
#endif
        return false;
    }
    else
    {
#ifdef _N_Debug_
        qDebug() << "ok[" << sql << ".";
#endif
        return true;
    }
    return true;
}

bool CSQLManager::isTableExist(QSqlDatabase db, QString tableName)
{
    QSqlQuery sqlQuery(db);
    sqlQuery.exec(QString("select count(*) from sqlite_master where type='table' and name='%1'").arg(tableName));
    if(sqlQuery.next())
    {
        if(sqlQuery.value(0).toInt()==0)
        {
            return false;
        }else{
            return true;
        }
    }
    return false;
}

void CSQLManager::addSrcData()
{

}
